One or more aspects of the present invention relate to program debugging, and more specifically, to a program debugger and program debugging.
Generally speaking, many programs each is typically composed of a header file (e.g., a header file extension in the C++ language is .h) and a definition file. The header file may serve as a carrier file containing class definitions, functionality functions, and data interface declarations and is mainly used for saving declarations for a program and playing a descriptive role. The definition file is used for saving implementations for a program. Usually, a program's header file contains defined class files, and one class contains class member variables and class member functions.
A program written in an object-oriented programming language that requires compiling and linking to form an executable file experiences the following steps from writing to final running. Firstly, a programmer writes a source program, and then, the programmer compiles the source program using a compiler, translating the source program into an object program in a binary form, wherein the compiling is conducted with a source program file as a unit. One application program might have several source files, therefore several object files or object programs, such as files with the extension of .o will be generated separately by the compiling. Next, the programmer uses a linker or binder to link all object programs resulting from the compiling of one program, system's library files and other information provided by the system to form an executable binary file, such as an .exe file. Finally, the programmer may run the resulting executable binary file, thereby obtaining a running result.
When a header file not only declares a class member function but also defines its implementation, and a compiler compiles a source file containing this header file and calling the member function, the compiler marks this function as a weak symbol (or referred to as a weak function) in a corresponding object file so as to allow multiple source files to call this class member function; otherwise, when a linker links them together, the linker will report an error. For weak functions corresponding to a same function name in multiple object files, the linker selects only one of them as an actually called function when perform the linking. Some linkers remove redundant weak function entities, while others retain all weak function entities. If the implementation of a member function of a class is defined within the class member body, then the member function is usually processed by the compiler into an inline function. However, the linker has to retain multiple weak function entities in order to realize function pointer calling.
A debugger is a tool that can be used for debugging an executable file with debug information, and its main functions are to maintain the program running, view information during the program running, such as register information, stack information, variable information, memory information, etc., and modify a program execution flow. To accomplish these functions, first of all, a running program needs to trigger a breakpoint and then stop. The breakpoint comprises a line number breakpoint and a function breakpoint. When setting a breakpoint, the debugger needs the debug information, which mainly comprises line number entities and debug information entities (DIE, which may take the format of dwarf) describing functions, variables and calling relationships, etc. and the debug information is generated during compiling and assembling.
Since there will be multiple debug information entities and corresponding line number entities for multiple weak functions, although some linkers relocate the debug information and others do not process the debug information, the debug information corresponding to a final executable file will retain debug information entities and corresponding line number entities for multiple weak functions. Then a problem arises: when a debugger sets breakpoints for these class member functions, the debugger has to find the debug information entities of all weak functions and set multiple breakpoints, or when a debugger sets line number breakpoints for class member function entities defined within a header file, the debugger also needs to find all line number entities and set multiple breakpoints. If there are 1000 or more files containing such a header file in a program, the debugger has to find 1000 or more debug information entities or line number entities and set 1000 or more breakpoints. When setting the same breakpoint again, the debugger repeats the effort to find 1000 or more debug information entities or line number entities and set multiple breakpoints.